package com.example.maple.ccsclient.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.example.maple.ccsclient.R;
import com.example.maple.ccsclient.adapter.GroupAdapter;
import com.example.maple.ccsclient.adapter.JazzyPagerAdapter;
import com.example.maple.ccsclient.instance.DataInfoInstance;
import com.example.maple.ccsclient.interfaces.IPicDetailView;
import com.example.maple.ccsclient.model.PicModel;
import com.example.maple.ccsclient.presenter.PicDetailPresenter;
import com.example.maple.ccsclient.utils.SharedUtils;
import com.example.maple.ccsclient.view.JazzyViewPager;
import com.example.maple.ccsclient.view.OnPagerSliding;
import com.example.maple.ccsclient.view.SlidingBaseView;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;

import java.net.URL;
import java.util.ArrayList;

public class PicDetailActivity extends Activity implements IPicDetailView {


	LinearLayout mSave = null;
	LinearLayout mShare = null;
	//LinearLayout mEdit = null;
	LinearLayout mBrush = null;

	LinearLayout mMenu = null;

	RelativeLayout main = null;

	private int mIndex;
	PicDetailPresenter mPicDetailPresenter = null;
	JazzyPagerAdapter mJazzyPagerAdapter = null;
	JazzyViewPager mJazzyViewPager = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		Fresco.initialize(this);
		mPicDetailPresenter = new PicDetailPresenter(this, this);
		setContentView(R.layout.activity_pic_detail);
		findView();

	}

	public static void startAction(Context context, int index) {
		Intent intent = new Intent(context, PicDetailActivity.class);
		intent.putExtra("index", index);
		context.startActivity(intent);

	}

	private void findView() {

		mIndex = getIntent().getIntExtra("index", 0);

		mJazzyViewPager = (JazzyViewPager) findViewById(R.id.jazzyViewPager);
		mJazzyPagerAdapter = new JazzyPagerAdapter(this, mJazzyViewPager, DataInfoInstance.getInstance().getPicModels());
		mJazzyViewPager.setAdapter(mJazzyPagerAdapter);
		mJazzyViewPager.setCurrentItem(mIndex);
		mSave = (LinearLayout) findViewById(R.id.save);
		mBrush = (LinearLayout) findViewById(R.id.brush);
	//	mEdit = (LinearLayout) findViewById(R.id.edit);
		mShare = (LinearLayout) findViewById(R.id.share);
		mMenu = (LinearLayout) findViewById(R.id.menu);
		main = (RelativeLayout) findViewById(R.id.main);

		mJazzyViewPager.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				if (mMenu.getVisibility() == View.VISIBLE) {
					mMenu.setVisibility(View.GONE);
				} else {
					mMenu.setVisibility(View.VISIBLE);
				}
			}
		});

		mJazzyViewPager.setOnPagerSilding(new OnPagerSliding() {
			@Override
			public void sliding(int index) {
				if (mMenu.getVisibility() == View.VISIBLE) {
					mMenu.setVisibility(View.GONE);
				}
				mIndex = index;
			}
		});

		mSave.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				PicModel picModel = DataInfoInstance.getInstance().getPicModels().get(mIndex);
				mPicDetailPresenter.savePic(picModel.getCImages(), picModel.getChar());
			}
		});

		mShare.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				SharedUtils.showShare(PicDetailActivity.this, "分享");
			}
		});

	/*	mEdit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				showDialog("编辑");
				PicChoiceActivity.startAction(PicDetailActivity.this);
			}
		});
*/
		mBrush.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				showDialog("描红");

			}
		});


	}


	@Override
	public void showDialog(String toastText) {
		Toast.makeText(PicDetailActivity.this, toastText, Toast.LENGTH_SHORT).show();
	}


	//描红
	public Bitmap brush(Bitmap oldBitmap) {
		Bitmap bitmap = null;

		return bitmap;
	}


}
